﻿using System;
using System.Linq.Expressions;

namespace ViewModelMapper
{
    public class Map<T, U>
    {
        public Expression<Func<T, object>> MapFrom { get; private set; }
        public Expression<Func<U, object>> MapTo { get; protected set; }

        public Direction Direction { get; protected set; }
        public Func<T, U, bool> Constraint { get; protected set; }

        public Map(Expression<Func<T, object>> from)
        {
            this.MapFrom = from;
        }

        public Map(Expression<Func<T, object>> from, Expression<Func<U, object>> to, Direction direction)
        {
            this.MapFrom = from;
            this.MapTo = to;
            this.Direction = direction;
        }   

        public DirectedMap<T, U> ToAndFrom(Expression<Func<U, object>> to)
        {
            return new DirectedMap<T, U>(this.MapFrom, to, Direction.ToAndFrom);
        }

        public DirectedMap<T, U> To(Expression<Func<U, object>> to)
        {
            return new DirectedMap<T, U>(this.MapFrom, to, Direction.To);
        }

        public DirectedMap<T, U> From(Expression<Func<U, object>> to)
        {
            return new DirectedMap<T, U>(this.MapFrom, to, Direction.From);
        }

    }
}
